package com.lepu.app.fun.knowledge.bean;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class Article implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 3951108850817741240L;

	public String RefreshTime;//detailInfo
	
	public String ArticleContent;//文章详情接口的字段
	
	public String ArticleID;//	文章ID
	public String ArticleTitle;//	文章标题
	public String ArticleDescription;//	文章简介
	public String ACID;//	所属分类ID
	public String ACTitle;//	类型标题
	public String PublishDate;//	发布时间
	public String LinkURL;//	原文链接
	public String Cover;//	封面图地址
	public String Video;//	视屏地址
	public String LinkTargetType;//	链接类型
	public String LinkTargetID;//	目标ID
	public String ViewCount;//	浏览次数
	
	//new add
	public String ArticleTag;
	public String AuthorID;//作家专栏banner
	
	public String DisplayType;// 1-普通文章；2-系列文章；3-专栏文章、
	public String ContentType;// 1-图文（默认）；2-视频

	public static ArrayList<Article> parseJsonData(String dataString) {
		String result = "";
		try {
			JSONObject jsonObject = new JSONObject(dataString);
			JSONObject obj1 = (JSONObject) jsonObject.get("Result");
			JSONArray dataArray = (JSONArray) obj1.get("ListInfo");
			
			result = dataArray.toString();
		} catch (JSONException e) {
			e.printStackTrace();
		}

		Gson gson = new Gson();
		ArrayList<Article> articleArraylist = gson.fromJson(result,new TypeToken<List<Article>>() {}.getType());
		return articleArraylist;
	}
	
	public static Article parseSimpleData(String dataString) {
		String result = "";
		try {
			JSONObject jsonObject = new JSONObject(dataString);
			JSONObject obj1 = (JSONObject) jsonObject.get("Result");
			JSONObject obj2 = (JSONObject) obj1.get("DetailInfo");
			
			result = obj2.toString();
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		Gson gson = new Gson();
		Article item = gson.fromJson(result,new TypeToken<Article>() {}.getType());
		return item;
	}
}
